package com.yjhb.android.sbz.mvp.follow;

import com.yjhb.android.sbz.App;
import com.yjhb.android.sbz.entity.Follow;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/11/25 9:51
 */
public class FollowPresenter extends ConventionPresenter<FollowView> {
    private final String TAG = "FollowPresenter";

    public FollowPresenter(FollowView followView) {
        super(followView);
    }

    @Override
    protected void onDestroy() {

    }


    public void cancelFollow(Integer userId){
        if (view!=null){
            view.onWait("处理中...");
        }
        HttpTool.request(model.follow(userId, 2), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view!=null){
                    view.onCancelSuccess();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view!=null){
                    view.onFailure(code, msg);
                }
            }
        });
    }

    /**
     * 关注列表
     *
     * @param pageIndex
     */
    public void getSubscribe(int pageIndex) {
        if (checkUnLogin()) return;
        HttpTool.request(model.getSubscribe(App.userInfo.getId(), pageIndex), new HttpObserver<List<Follow>>() {
            @Override
            public void onResult(List<Follow> data) {
                if (view != null) {
                    view.onSuccess(data, pageIndex != 1);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    public void getFans(int page) {
        if (checkUnLogin()) return;
        HttpTool.request(model.getFans(App.userInfo.getId(), page), new HttpObserver<List<Follow>>() {
            @Override
            public void onResult(List<Follow> data) {
                if (view != null) {
                    if (page == 1)
                        view.onSuccess(data, false);
                    else
                        view.onSuccess(data, true);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) view.onFailure(code, msg);
            }
        });
    }
}
